summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/jni/id_cache.cpp
blob: 2955122be8191e0ae79df7b6143e1695155e6078 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "jni/id_cache.h"

static JavaVM* s_java_vm;
static jclass s_native_library_class;
static jmethodID s_exit_emulation_activity;

namespace IDCache {

JNIEnv* GetEnvForThread() {
    thread_local static struct OwnedEnv {
        OwnedEnv() {
            status = s_java_vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
            if (status == JNI_EDETACHED)
                s_java_vm->AttachCurrentThread(&env, nullptr);
        }

        ~OwnedEnv() {
            if (status == JNI_EDETACHED)
                s_java_vm->DetachCurrentThread();
        }

        int status;
        JNIEnv* env = nullptr;
    } owned;
    return owned.env;
}

jclass GetNativeLibraryClass() {
    return s_native_library_class;
}

jmethodID GetExitEmulationActivity() {
    return s_exit_emulation_activity;
}

} // namespace IDCache